#!/bin/bash

echo "##Num   hO  hS  s##" > bindingStrenth.dat

for i in `seq 1 1 200`
do
hO=`sort -rn -k 2 QpluhO$i.dat |head -1|awk '{print $2}'`
hS=`sort -rn -k 2 QpluhS$i.dat |head -1|awk '{print $2}'`
s=`sort -rn -k 2 Qplus$i.dat |head -1|awk '{print $2}'`
 echo $i   $hO  $hS  $s >> bindingStrenth.dat
done

 awk 'NR>1 && $3>0.8 {print $1}' bindingStrenth.dat> bindingNumber.dat

tOne=0
tSecond=0
ts=0
 echo "##Num   tOne  tSecond  tsheet (ns) ##" > bindingTime.dat
while read j
do
tOne=`awk '$2>0.8 {print NR}' QpluhO$j.dat| awk 'NR==1 {print $1/100}'` ### ns
tSecond=`awk '$2>0.8 {print NR}' QpluhS$j.dat| awk 'NR==1 {print $1/100}'` ### ns
ts=`awk '$2>0.8 {print NR}' Qplus$j.dat| awk 'NR==1 {print $1/100}'` ### ns
 echo $j   $tOne  $tSecond  $ts >> bindingTime.dat
tOne=0
tSecond=0
ts=0
done< bindingNumber.dat

tOnemean=`awk 'NR>1 && NR<22{sum+=$2;count++}END{print sum/count}' bindingTime.dat`
tSecondmean=`awk 'NR>1 && NR<22{sum+=$3;count++}END{print sum/count}' bindingTime.dat`
tsmean=`awk 'NR>1 && NR<22{sum+=$4;count++}END{print sum/count}' bindingTime.dat`
echo "mean binding time of REGION1--hOne(ns): " $tOnemean
echo "mean binding time of REGION3--hSecond(ns): " $tSecondmean
echo "mean binding time of REGION2--sheet(ns): " $tsmean
